package com.glink.common.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 查询日志转码, 防止日志攻击注入
 *
 * @author rcl026@163.com
 * @since 2023/12/13
 */
public abstract class LogUtil {
    public static String encode(Object obj) {
        if (Objects.isNull(obj)) {
            return null;
        } else if (obj instanceof String) {
            return StringUtils.replace(obj.toString(), "\n", " ");
        } else {
            if (StringUtils.length(obj.toString()) <= 0) {
                return " ";
            } else {
                return StringUtils.replace(obj.toString(), "\n", " ");
            }
        }
    }
}
